#include once "tcomm.bi"

sub thread_a( byval _cc as any ptr )
    var cc = cast(CommChannel ptr,_cc)

    while 1
        var m = cc->recv()
        while m = 0
            m = cc->recv()
        wend
        ? "Recieved message: " & m->c
        if m->c = 0 then
            delete m
            exit while
        end if
        delete m
    wend

end sub

scope 'main

    var cc = new CommChannel()
    var tid = threadcreate( @thread_a, cc )

    sleep 100

    for n as integer = 10 to 0 step -1
        cc->send(new Message(n))
    next

    threadwait tid

    delete cc

end scope
